<? include "../connect.php"; ?>
<?php
ob_start();
session_start();
include "checksession.php";
date_default_timezone_set('Asia/Bangkok');
$emp_id=$_GET['emp_id'];

require('fpdf.php');
define('FPDF_FONTPATH','font/');

//$test = $_GET['emp_id'];

class PDF extends FPDF{

	function conv($string){
	return iconv('UTF-8', 'TIS-620', $string);
	}

	function Header(){
			
			$this->SetLeftMargin( 20 );
			$this->AddFont('angsa','','angsa.php');
			$this->AddFont('angsana','B','angsab.php');
			$this->SetFont('angsana','B',10);
			$this->SetFont('angsa','',14);
			$this->AddFont('tahoma','','tahoma.php');
	 		$this->SetFont('tahoma','',10);
			$this->Text(20,15,iconv( 'UTF-8','TIS-620',"No. 13-S................" ),0,1,"L");
			$this->Text(55,15,iconv( 'UTF-8','TIS-620',"Date/Time..................................."),0,1,"L");
			$this->SetFont('tahoma','',9);
			$this->Text(267,12,iconv( 'UTF-8','TIS-620',"F-IT-004 R06"),0,1,"R");
			$this->Ln(8);

			$this->AddFont('browallia','','browa.php');
			$this->AddFont('browallia','B','browab.php');
			$this->AddFont('browallia','I','browai.php');
			$this->AddFont('browallia','BI','browaz.php');
			$this->SetFont('browallia','B',16);
			$this->SetFillColor(194,194,194);

			$this->Cell(267,8,iconv('UTF-8','TIS-620','ใบทะเบียนประวัติสิทธิ์การเข้าถึงข้อมูล'),1,1,'C',true);
			$this->Ln(7);
			$this->Text(30,34,iconv( 'UTF-8','TIS-620',"ADD"),0,1,"C");
			$this->Text(52,34,iconv( 'UTF-8','TIS-620',"CANCEL ALL"),0,1,"C");
			$this->Text(230,34,iconv( 'UTF-8','TIS-620',"Reference:"),0,1,"C");
			$this->Image('../images/true.jpg',23,29,5);
			
			$this->Text(73,14.5,iconv( 'UTF-8','TIS-620',''.$_GET['']),0,1,"C");
			$this->Text(35,14.5,iconv( 'UTF-8','TIS-620',''.$_GET['']),0,1,"C");
			$this->Text(252,34,iconv( 'UTF-8','TIS-620','13-U'.$_GET['']),0,1,"C");

			$this->Ln(7);
			$this->Cell(40,8,iconv('UTF-8','TIS-620','Employee ID : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['emp_id']),1,0,'C');
			$this->Cell(7,8,iconv('UTF-8','TIS-620',''),0,0,'C');
			$this->Cell(40,8,iconv('UTF-8','TIS-620','Department : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['departname']),1,1,'C');

			$this->Cell(40,8,iconv('UTF-8','TIS-620','Computer ID : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['comid']),1,0,'C');
			$this->Cell(7,8,iconv('UTF-8','TIS-620',''),0,0,'C');
			$this->Cell(40,8,iconv('UTF-8','TIS-620','Start Date : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['startdate']),1,1,'C');

			$this->Cell(40,8,iconv('UTF-8','TIS-620','Name (ENG) : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['nameEng']),1,0,'C');
			$this->Cell(7,8,iconv('UTF-8','TIS-620',''),0,0,'C');
			$this->Cell(40,8,iconv('UTF-8','TIS-620','Username : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['username']),1,1,'C');

			$this->Cell(40,8,iconv('UTF-8','TIS-620','Surname (ENG) : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['surname']),1,0,'C');
			$this->Cell(7,8,iconv('UTF-8','TIS-620',''),0,0,'C');
			$this->Cell(40,8,iconv('UTF-8','TIS-620','Remark : '),1,0,'R');
			$this->Cell(90,8,iconv('UTF-8','TIS-620',''.$_GET['remark']),1,1,'C');

			$this->Ln(10);

			$this->SetFont('browallia','B',14);
			$this->Cell(10,7.5,iconv('UTF-8','TIS-620','Item'),'LTR',0,'C',true);
			$this->Cell(60,7.5,iconv('UTF-8','TIS-620','Description'),'LTR',0,'C',true);
			$this->Cell(30,7.5,iconv('UTF-8','TIS-620','Permission'),'1',0,'C',true);
			$this->Cell(22,7.5,iconv('UTF-8','TIS-620','Owner'),'LTR',0,'C',true);
			$this->Cell(29,7.5,iconv('UTF-8','TIS-620','Cancel'),'1',0,'C',true);
			$this->Cell(29,7.5,iconv('UTF-8','TIS-620','By Requestor'),'1',0,'C',true);
			$this->Cell(29,7.5,iconv('UTF-8','TIS-620','For IT Staff'),'1',0,'C',true);
			$this->Cell(29,7.5,iconv('UTF-8','TIS-620','By Authorized'),'1',0,'C',true);
			$this->Cell(29,7.5,iconv('UTF-8','TIS-620','By Supervisor'),'1',1,'C',true);

			$this->Cell(10,7.5,iconv('UTF-8','TIS-620',''),'LRB',0,'C',true);
			$this->Cell(60,7.5,iconv('UTF-8','TIS-620',''),'LRB',0,'C',true);
			$this->Cell(10,7.5,iconv('UTF-8','TIS-620','R'),'1',0,'C',true);
			$this->Cell(10,7.5,iconv('UTF-8','TIS-620','W'),'1',0,'C',true);
			$this->Cell(10,7.5,iconv('UTF-8','TIS-620','M'),'1',0,'C',true);
			$this->Cell(22,7.5,iconv('UTF-8','TIS-620','Signature'),'LRB',0,'C',true);
			$this->SetFont('browallia','B',11);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','Signature'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','D/M/Y'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','Signature'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','D/M/Y'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','Signature'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','D/M/Y'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','Signature'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','D/M/Y'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','Signature'),'1',0,'C',true);
			$this->Cell(14.5,7.5,iconv('UTF-8','TIS-620','D/M/Y'),'1',1,'C',true);

		}
	
	function Footer(){

			$this->SetFont('browallia','',16);
			$this->SetY(-15);
			$this->Cell(267,7,iconv('UTF-8','TIS-620','Remark : Standard Drive F: , G: , I: , P: , T: , R: , U: '),1,0,'L');
			}

	function FancyTable($header,$data,$rowdb,$date){
			
			$this->SetFillColor(255,255,255);
			$this->SetTextColor(0);
			$this->SetDrawColor(0,0,0);
			$this->SetLineWidth(.3);
			$this->SetFont('','B');
		//	$this->Text(73,14.5,iconv( 'UTF-8','TIS-620',''.$date),0,1,"C");
		//	$this->Text(200,14.5,iconv( 'UTF-8','TIS-620',''.$rowdb),0,1,"C");
			$w=array(25,55,30,25);
		//	for($i=0;$i<count($header);$i++)
 
		//		$this->Cell($w[$i],4,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C',true);
		//	$this->Ln();
			//Color and font restoration
			$this->SetFillColor(255,255,255);
			$this->SetTextColor(0);
			$this->SetFont('angsa','',14);
			//Data
			$fill=false;
			$sum=0;
			$i=1;
			$h=98;
			//$row;

			foreach($data as $row){
			
				if($i > 14){
				
				$this->Cell(10,7,$i,1,0,'C',$fill);
                $this->SetFont('angsa','',10);
				$this->Cell(60,7,$row['per_description'],1,0,'L',$fill);
				$this->SetFont('angsa','',14);
				if($row['per_permission'] == 'r'){
				$this->Cell(10,7,'r',1,0,'C',$fill);
				$this->Image('../images/true.jpg',93,$h,5);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				}
				if($row['per_permission'] == 'w'){
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'w',1,0,'C',$fill);
				$this->Image('../images/true.jpg',103,$h,5);
				$this->Cell(10,7,'',1,0,'C',$fill);
				}
				if($row['per_permission'] == 'm'){
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'m',1,0,'C',$fill);
				$this->Image('../images/true.jpg',113,$h,5);
				}
				$this->Cell(22,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Ln();
				$fill=!$fill;
				$i++;
				$h=$h+7;
				if($h > 189){
					$h=98;
				}
			}else{
				
				$this->Cell(10,7,$i,1,0,'C',$fill);
				$this->SetFont('angsa','',10);
				$this->Cell(60,7,$row['per_description'],1,0,'L',$fill);
                $this->SetFont('angsa','',14);
				if($row['per_permission'] == 'r'){
				$this->Cell(10,7,'r',1,0,'C',$fill);
				$this->Image('../images/true.jpg',93,$h,5);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				}
				if($row['per_permission'] == 'w'){
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'w',1,0,'C',$fill);
				$this->Image('../images/true.jpg',103,$h,5);
				$this->Cell(10,7,'',1,0,'C',$fill);
				}
				if($row['per_permission'] == 'm'){
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'m',1,0,'C',$fill);
				$this->Image('../images/true.jpg',113,$h,5);
				}
				$this->Cell(22,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Ln();
				$fill=!$fill;
				$i++;
				$h=$h+7;
				if($h > 189){
					$h=98;
				}

			}
						
			}
/*
			for($i=1;$i<=15;$i++)
			{
				$this->Cell(10,7,$i,1,0,'C',$fill);
				$this->Cell(60,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(10,7,'',1,0,'C',$fill);
				$this->Cell(22,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
				$this->Cell(14.5,7,'',1,0,'C',$fill);
	
				$this->Ln();
				$fill=!$fill;
			}
	*/	
		
	
			}

}
$pdf=new PDF();
//*** Load MySQL Data ***//
include "../connect.php";
$strSQL = "SELECT * FROM employee INNER JOIN mail ON employee.emp_id = mail.emp_id INNER JOIN depart ON employee.de_id = depart.id INNER JOIN permissionfile ON permissionfile.emp_id = employee.emp_id where employee.emp_id ='$emp_id' order  by per_id asc";
$objQuery = mysql_query($strSQL);
mysql_query("set NAMES'TIS620'");
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
	$result = mysql_fetch_array($objQuery);
	$result['per_description'] = iconv("UTF-8", "ISO-8859-11",$result['per_description']);
	array_push($resultData,$result);

	if($result['mail_authorizedDate'] == "0000-00-00 00:00:00"){
		$result['mail_authorizedDate'] = "";
	}
	if($result['mail_requestUserDate'] == "0000-00-00 00:00:00"){
		$result['mail_requestUserDate'] = "";
	}
	if($result['mail_staffITdate'] == "0000-00-00 00:00:00"){
		$result['mail_staffITdate'] = "";
	}
	if($result['mail_authorizedConDate'] == "0000-00-00 00:00:00"){
		$result['mail_authorizedConDate'] = "";
	}
	if($result['mail_supervisorDate'] == "0000-00-00 00:00:00"){
		$result['mail_supervisorDate'] = "";
	}
}
//************************//
$pdf->AddPage('L','A4');
$pdf->SetLeftMargin( 20 );
//$pdf->SetAutoPageBreak(true , 5);
$pdf->SetAutoPageBreak(true,10);
$pdf->AddFont('browallia','','browa.php');
$pdf->AddFont('browallia','B','browab.php');
$pdf->AddFont('browallia','I','browai.php');
$pdf->AddFont('browallia','BI','browaz.php');
$pdf->SetFont('browallia','B',16);
$pdf->SetFillColor(194,194,194);
//$date=$result['per_createDate'];

$pdf->FancyTable($header,$resultData,$i,$date);

$pdf->Output();
?>